<extend name="Public:innerbase" />
<block name="css">
<style type="text/css">
	.icon-image{
		width: 30px;height:30px;
	}
</style>
</block>
<block name="content">
<div class="container-fluid">
	<div class="page-header wm-page-header">
		<h4>微网站底部菜单设置</h4>
		<if condition="$pid neq 0">
		<a href="{:U('Homemenu/index')}">返回</a>
		</if>
	</div>
	<div class="tabbable-custom">
	<if condition="$pid eq 0">
	<ul class="nav nav-tabs wm-tabs">
		<li class="active"><a href="javascript:void(0)">菜单项设置</a></li>
		<li><a href="{:U('Homemenu/style')}" target="_self">菜单风格</a></li>
		<li><a href="{:U('Homemenu/set')}" target="_self">菜单颜色与版权</a></li>
	</ul>
	</if>
	<button class="btn btn-primary btn-edit" url="{:U('Homemenu/edit',['pid'=>$_GET['pid']])}" style="margin:10px 0;">添加菜单项</button>
	<table class="table wm-table-bordered table-stripped">
		<THEAD>
			<TR>
				<TH>菜单名称</TH>
				<TH>显示顺序</TH>
				<TH>菜单图标</TH>
				<TH>外链地址</TH>
				<TH>首页显示</TH>
				<TH>操作</TH>
			</TR>
        </THEAD>
		<tbody>
			<volist name="menus" id="vo">
			<tr>
			<td>{$vo.name}</td>
			<td>{$vo.ordernum}</td>
			<td style="background-color:#ace;">
				<if condition="$vo['picurl'] neq ''">
				<img src="{$vo.picurl}" class="icon-image"  />
				</if>
			</td>
			<td><div class="wrap-text" style="max-width:140px;">{$vo.url}</div></td>
			<td><eq name="vo.status" value="1">显示<else/>不显示</eq></td>
			<td>
				<if condition="$vo['pid'] eq 0"><a class="btn btn-info btn-xs" href="{:U('Homemenu/index',array('pid'=>$vo['id']))}">子菜单</a></if>
				<button class="btn btn-primary btn-xs btn-edit" url="<if condition="$vo['pid'] eq 0">{:U('Homemenu/edit',array('id'=>$vo['id']))}<else/>{:U('Homemenu/edit',array('id'=>$vo['id'],'pid'=>$vo['pid']))}</if>">编辑</button>
				<a class="btn btn-danger btn-xs" href="<if condition="$vo['pid'] eq 0">{:U('Homemenu/del',array('id'=>$vo['id']))}<else/> {:U('Homemenu/del',array('id'=>$vo['id'],'pid'=>$vo['pid']))}</if>">删除</a>
			</td>
			</tr>
			</volist>
		</tbody>
	</table>
	</div>
</div>

<!-- Modal -->
<div class="modal fade" id="menuModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
	<div class="modal-dialog modal-lg">
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
				<h4 class="modal-title" id="myModalLabel">新建菜单项</h4>
			</div>
			<div class="modal-body">
				<iframe id="modalFrame" frameBorder="0" src="{:U('User/Homemenu/edit')}" style="width:100%;height:400px;border:0;" ></iframe>
			</div>
			<div class="modal-footer">
				<button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
				<button id="btnSave" type="button" class="btn btn-primary">保存</button>
			</div>
		</div>
	</div>
</div>
</block>
<block name="js">
<script type="text/javascript">
$('.btn-edit').click(function(){
	var src = $(this).attr('url');
	var timestamp = (new Date()).getTime();
	if(src.indexOf('?')>0){
		src+='&timestamp='+timestamp;
	}
	else{
		src+='?timestamp='+timestamp;
	}
	$('#modalFrame').attr('src',src);
	$('#menuModal').modal({
		'backdrop': 'static',
		'keyboard': false
	});
});

$('#btnSave').on('click', function (e) {
	var ret = $('#modalFrame')[0].contentWindow.submit('callback');
})

/**
 * @method callback 子窗口数据提交成功时调用
 */
function callback(id){
	$('#menuModal').modal('hide');
	location.reload();
}
</script>
</block>